#ifndef __MY_EVENTS_H__
#define __MY_EVENTS_H__

#include "os_api.h"
// #include "kal_general_types.h"

#if defined(__LINUX_OS__)
#include <pthread.h>
#include <stdio.h>
#include <unistd.h>
#include "os_config.h"

#define MYEVENTS_NAME_LEN_MAX  16 // 8  RT_NAME_MAX

struct my_events
{
    char  pname[MYEVENTS_NAME_LEN_MAX];
    pthread_cond_t cond;
    pthread_mutex_t mtx;
    int set ;
};

typedef struct my_events my_events_t;
typedef struct my_events * my_events_id;

#define KAL_AND 	1   //  &  clear
#define KAL_OR  	2   //  |  set



#else//#if defined(__LINUX_OS__)

#include "os_config.h"
// #include "globle_include.h"



#define MYEVENTS_NAME_LEN_MAX  RT_NAME_MAX // 8  RT_NAME_MAX

struct my_events
{
    char  pname[MYEVENTS_NAME_LEN_MAX];
    event_handle_t event_group;
};

typedef struct my_events my_events_t;
typedef struct my_events * my_events_id;

#define KAL_AND 	1   //  &  clear
#define KAL_OR  	2   //  |  set

/*
#define KAL_CONSUME           1 //NU_OR_CONSUME
#define KAL_AND               2 //NU_AND
#define KAL_AND_CONSUME       3 //NU_AND_CONSUME
#define KAL_OR                0 //NU_OR
#define KAL_OR_CONSUME        1 //NU_OR_CONSUME
#define KAL_NO_SUSPEND        0 //NU_NO_SUSPEND
#define KAL_SUSPEND           0xFFFFFFFF //NU_SUSPEND
*/




extern int my_events_clear_bits(my_events_id events_id, uint32_t event);


extern int my_events_wait_op(my_events_id events_id, uint32_t event, uint32_t operation);


#if defined(ENABLE_FREERTOS_SYSAPI)
extern int my_events_set_isr(my_events_id events_id, uint32_t event);
extern int my_events_clear_isr(my_events_id events_id);
#else
#define my_events_set_isr			my_events_set
#define my_events_clear_isr			my_events_clear
#endif

#endif

extern my_events_id my_events_create(const char * events_name);
extern int my_events_free(my_events_id *events_id);
extern int my_events_set(my_events_id events_id, uint32_t event);
extern int my_events_wait(my_events_id events_id, uint32_t event);
extern int my_events_clear(my_events_id events_id);
extern int my_events_wait_tick(my_events_id events_id, uint32_t event, tick_timeout_t tick);



#endif

